package com.menhai.personmanagement.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.menhai.personmanagement.entity.TjInspectphysical;
import com.menhai.personmanagement.entity.co.TjInspectphysicalCo;
import com.menhai.personmanagement.entity.co.TjSkCo;
import com.menhai.personmanagement.entity.vo.TjInspectphysicalVo;
import com.menhai.personmanagement.entity.vo.TjInspectphysicalfrontVo;
import com.menhai.personmanagement.services.ITjInspectphysicalService;
import com.menhai.personmanagement.utils.ExportSysUserInfoExcel;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shikun
 * @since 2022-01-12
 */

@Slf4j
@RestController
@RequestMapping("/tj-inspectphysical")
public class TjInspectphysicalController {

     @Autowired
     private ITjInspectphysicalService tjnspectphysicalService;

     @RequestMapping("/save/{account}")
     public int save(@RequestHeader("level") String level, @PathVariable("account") String account, TjInspectphysical tjInspectphysical){
          return tjnspectphysicalService.save(level, tjInspectphysical, account);
     }

     @RequestMapping("/getAllInspectByUserName")
     public List getAllInspectByUserName(@Param("name") String name,@RequestHeader("level") String level,@Param("pagesize") int pagesize,@Param("pagenum") int pagenum){
          return tjnspectphysicalService.getAllInspectByUserName(name,level,pagesize,pagenum);
     }

     @RequestMapping("/findInspectInfoById")
     public TjInspectphysical findInspectInfoById(@Param("id") int id){
          return tjnspectphysicalService.findInspectInfoById(id);
     }

     @RequestMapping("/updateInspectInfo")
     public int updateInspectInfo(TjInspectphysical tjInspectphysical){
          return tjnspectphysicalService.updateInspectInfo(tjInspectphysical);
     }

     @RequestMapping("/addProposalSubmit")
     public int addProposalSubmit(TjInspectphysical tjInspectphysical){
          return tjnspectphysicalService.addProposalSubmit(tjInspectphysical);
     }

     @RequestMapping("/getPageTotal")
     public int getPageTotal(@RequestHeader("level") String level,@Param("name") String name){
          return tjnspectphysicalService.getPageTotal(level,name);
     }

     /**
      * @describe 体检首页
      * @param superiorCode
      * @Return com.menhai.personmanagement.entity.vo.FrontPageVo
      * @Date 2022/1/12 15:14
      * @author shikun
      */
     @RequestMapping("/bodycheckupfront")
     public TjInspectphysicalfrontVo bodycheckupfront(@Param("superiorCode") String superiorCode){
          return tjnspectphysicalService.bodycheckupfront(superiorCode);
     }

     /**
      * @describe 体检首页 年龄分类
      * @param superiorCode
      * @Return java.util.List<com.menhai.personmanagement.entity.vo.TjInspectphysicalfrontVo>
      * @Date 2022/1/13 10:32
      * @author shikun
      */
     @RequestMapping("/bodydetectagelayered")
     public List<TjInspectphysicalfrontVo> bodydetectagelayered(@Param("superiorCode") String superiorCode){
          return tjnspectphysicalService.bodydetectagelayered(superiorCode);
     }

     /**
      * @describe  体检首页 性别
      * @param superiorCode
      * @Return java.util.List<com.menhai.personmanagement.entity.vo.TjInspectphysicalfrontVo>
      * @Date 2022/1/13 10:53
      * @author shikun
      */
     @RequestMapping("/bodydetesex")
     public List<TjInspectphysicalfrontVo> bodydetesex(@Param("superiorCode") String superiorCode){
          return tjnspectphysicalService.bodydetesex(superiorCode);
     }

     /**
      * @describe 每日体检数量
      * @param superiorCode
      * @Return java.util.List<com.menhai.personmanagement.entity.vo.TjInspectphysicalfrontVo>
      * @Date 2022/1/13 11:23
      * @author shikun
      */
     @RequestMapping("/dailybodycheck")
     public List<TjInspectphysicalfrontVo> dailybodycheck(@Param("superiorCode") String superiorCode){
          return tjnspectphysicalService.dailybodycheck(superiorCode);
     }

     @RequestMapping("/findHistoryByPeopleId")
     public List findHistoryByPeopleId(@Param("id") int id,@RequestHeader("level") String hosnum){
          return tjnspectphysicalService.findHistoryByPeopleId(id,hosnum);
     }

     @RequestMapping("/findHistoryByDate")
     public List findHistoryByDate(@Param("tian") int tian,@Param("date1") String date1,@Param("date2") String date2,@Param("mbpeopleId") int mbpeopleId,@Param("mbhosnum") String mbhosnum){
          System.out.println(tian+","+date1+","+date2+","+mbpeopleId+","+mbhosnum);
          return tjnspectphysicalService.findHistoryByDate(tian,date1,date2, mbpeopleId, mbhosnum);
     }

     @RequestMapping("/getAllInspect")
     public List getAllInspect(@RequestHeader("level") String hosnum,@Param("pagesize") int pagesize,@Param("pagenum") int pagenum){
          return tjnspectphysicalService.getAllInspect(hosnum,pagesize,pagenum);
     }


     @RequestMapping("/diseaserisk")
     public Page diseaserisk(@RequestHeader("level") String level, @Param("pagesize") int pagesize, @Param("pagenum") int pagenum, @Param("name") String name, @Param("risk") String risk){
          return tjnspectphysicalService.exprotDiseaserisk(level, pagesize, pagenum, name, risk, false);
     }

     @RequestMapping("/exprotDiseaserisk")
     public Page exprotDiseaserisk(@RequestHeader("level") String level, @Param("pagesize") int pagesize, @Param("pagenum") int pagenum,@Param("") String name, @Param("risk") String risk){
          return tjnspectphysicalService.exprotDiseaserisk(level, pagesize, pagenum, name, risk, true);
     }

     /**
      * @describe 每日工作量统计表
      * @param tjSkCo
      * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.menhai.personmanagement.entity.vo.TjInspectphysicalVo>
      * @Date 2022/2/23 11:55
      * @author shikun
      */
     @RequestMapping("/selectBycreateTime")
     public IPage<TjInspectphysicalVo> selectBycreateTime(TjSkCo tjSkCo){
          IPage<TjInspectphysicalVo> list = tjnspectphysicalService.selectBycreateTime(tjSkCo);
          return list;
     }

     /**
      * @describe 每日工作量统计表导出
      * @param tjSkCo
      * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.menhai.personmanagement.entity.vo.TjInspectphysicalVo>
      * @Date 2022/2/23 11:55
      * @author shikun
      */
     @RequestMapping("/exportBycreateTime")
     public void exportBycreateTime(HttpServletResponse response, TjSkCo tjSkCo) {
          try {
               List<TjInspectphysicalVo> list = tjnspectphysicalService.exportBycreateTime(tjSkCo);
               ServletOutputStream out = response.getOutputStream();
               new ExportSysUserInfoExcel().exportBycreateTime(list, out, response);
          } catch (IOException e) {
               e.printStackTrace();
          }
     }

     /**
      * @describe 每月工作量统计表
      * @param tjSkCo
      * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.menhai.personmanagement.entity.vo.TjInspectphysicalVo>
      * @Date 2022/2/23 16:39
      * @author shikun
      */
     @RequestMapping("/selectBymonthgrouping")
     public IPage<TjInspectphysicalVo> selectBymonthgrouping(TjSkCo tjSkCo){
          IPage<TjInspectphysicalVo> list = tjnspectphysicalService.selectBymonthgrouping(tjSkCo);
          return list;
     }

     /**
      * @describe 每月工作量统计表导出
      * @param response
      * @param tjSkCo
      * @Return void
      * @Date 2022/2/24 8:51
      * @author shikun
      */
     @RequestMapping("/exportBymonthgrouping")
     public void exportBymonthgrouping(HttpServletResponse response, TjSkCo tjSkCo) {
          try {
               List<TjInspectphysicalVo> list = tjnspectphysicalService.exportBymonthgrouping(tjSkCo);
               ServletOutputStream out = response.getOutputStream();
               new ExportSysUserInfoExcel().exportBymonthgrouping(list, out, response);
          } catch (IOException e) {
               e.printStackTrace();
          }
     }

     /**
      * @describe 个人体检患者查询导出
      * @param tjInspectphysicalCo
      * @Return java.lang.Object
      * @Date 2022/2/28 13:16
      * @author shikun
      */
     @RequestMapping(value = "/exportfinishbodycheckup")
     public void exportfinishbodycheckup(HttpServletResponse response, TjInspectphysicalCo tjInspectphysicalCo)  {
          try {
               List<TjInspectphysicalVo> list = tjnspectphysicalService.finishbodycheckuplist(tjInspectphysicalCo);
               ServletOutputStream out = response.getOutputStream();
               new ExportSysUserInfoExcel().finishbodycheckuplist(list, out, response);
          } catch (IOException e) {
               e.printStackTrace();
          }

     }

     @RequestMapping(value = "/cheshi")
     public void cheshi(HttpServletResponse response, TjInspectphysicalCo tjInspectphysicalCo)  {
          try {

               List<TjInspectphysicalVo> list = new ArrayList<>();

               TjInspectphysicalVo tjInspectphysicalVo = new TjInspectphysicalVo();

               list.add(tjInspectphysicalVo);

               ServletOutputStream out = response.getOutputStream();
               new ExportSysUserInfoExcel().cheshi(list, out, response);
          } catch (IOException e) {
               e.printStackTrace();
          }

     }


     @RequestMapping("/insertReport")
     public int insertReport(@Param("data") String data){
          return tjnspectphysicalService.insertReport(data);
     }

     /**
      * 查询中医体检记录列表
      * @param request
      * @param response
      * @param
      * @return
      * @throws Exception
      */
     @RequestMapping(value = "/getInspectPhysicalList", method = RequestMethod.POST)
     public Object getInspectPhysicalList(HttpServletRequest request, HttpServletResponse response, TjInspectphysicalCo tjInspectphysicalCo) throws Exception {
          String hosnumarray = request.getParameter("hosnumarray");
          tjInspectphysicalCo.setHosnumarray(hosnumarray.split(","));
          tjInspectphysicalCo.setHosnumstr(hosnumarray);
          IPage<TjInspectphysicalCo> list = tjnspectphysicalService.getInspectPhysicalList(tjInspectphysicalCo);
          return list;
     }

     /**
      * 左侧树
      * @param hosnum
      * @return
      */
     @RequestMapping("/getCunRenShu")
     public List<Map<String,Object>> getCunRenShu(HttpServletRequest request, HttpServletResponse response){
          //医院编号
          String hosnum = request.getParameter("hosnum");
          return tjnspectphysicalService.getCunRenShu(hosnum);
     }

}
